package com.education.web.zuul;

import com.education.web.common.core.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.zuul.RoutesRefreshedEvent;
import org.springframework.cloud.netflix.zuul.filters.RouteLocator;
import org.springframework.cloud.netflix.zuul.web.ZuulHandlerMapping;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RefreshRouteController {


    @Autowired
    private ZuulHandlerMapping zuulHandlerMapping;

    @Autowired
    private ApplicationEventPublisher publisher;

    @Autowired
    private RouteLocator routeLocator;


    @GetMapping("/refreshRoute")
    public Result refresh() {
        RoutesRefreshedEvent routesRefreshedEvent = new RoutesRefreshedEvent(routeLocator);
        publisher.publishEvent(routesRefreshedEvent);
        return Result.success();
    }

    @GetMapping("/watchRoute")
    public Result watchNowRoute() {
        //可以用debug模式看里面具体是什么
        return Result.success(zuulHandlerMapping.getHandlerMap());
    }


}
